package com.eleventwelve.iris.web.controller;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import org.opentides.controller.BaseCrudController;
import org.opentides.util.StringUtil;

import com.eleventwelve.iris.entity.Patient;
import com.eleventwelve.iris.service.PatientService;

public class PatientUploadFileController extends BaseCrudController<Patient> {
	private PatientService patientService;
	
	@Override
	protected Object formBackingObject(HttpServletRequest request)
			throws Exception {
		String patientId = request.getParameter("id");
		
		if(!StringUtil.isEmpty(patientId)){
			Patient patient = patientService.load(patientId);
			return patient;
		}

		return null;
	}
	
	@Override
	protected Map<String, Object> referenceData(HttpServletRequest request) throws Exception {
		Map<String, Object> map = new HashMap<String, Object>();
		String patientId = request.getParameter("id");
		
		if(!StringUtil.isEmpty(patientId)){
			Patient patient = patientService.load(patientId);
			map.put("currentPatient", patient);
			
			return map;
		}
		
		return null;
	}
	
	public void setPatientService(PatientService patientService) {
		this.patientService = patientService;
	}
}
